package com.leyou.search.controller;

import com.leyou.search.pojo.SearchRequest;
import com.leyou.search.pojo.SearchResult;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @author: Mr_Sun
 * @Date: 2018/9/14
 * @Time: 21:40
 */
@RestController
@RequestMapping
public class SearchController {
    @Autowired
    private SearchService searchService;
    /**
     * 搜索商品
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public ResponseEntity<SearchResult> search(@RequestBody SearchRequest request) {
        SearchResult result=  searchService.search(request);
        if (null==result) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);

    }
}
